package com.neusoft.ai.chat.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @author zzc
 * @since 2025/6/13 下午1:49
 */
@RestController
public class ChatAiController {

    @Autowired
    private ChatClient chatClient;

    //非流式响应输出
    @GetMapping("/chatai")
    public String chatai(@RequestParam(value = "message", defaultValue = "你是谁") String message){
        return chatClient.prompt()
                .user(message)
                .call()
                .content();
    }

    //流式响应输出
    @GetMapping(value = "/chataiStream", produces = "text/html;charset=UTF-8")
    public Flux<String> chatAiStream(@RequestParam(value = "message", defaultValue = "你是谁") String message){
        return chatClient.prompt()
                .user(message)
                .stream()
                .content();
    }
}
